package com.jie.deletefile.Weather;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.jie.deletefile.R;

import java.util.List;

/**
 * Created by 13952137957 on 2016/10/12.
 */
public class CityAdapter extends ArrayAdapter<String> {

    Context context;
    int resID;
    List<String> data;

    public CityAdapter(Context context, int resource, List<String> data) {
        super(context, resource);
        this.context = context;
        this.data = data;
        resID = resource;

    }

    public List<String> getData() {
        return data;
    }

    public void addfirst(String s) {
        data.add(0, s);
        notifyDataSetChanged();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(resID, null);

        }
        TextView textView = (TextView) convertView.findViewById(R.id.item_tv);
        textView.setText(data.get(position));
        return convertView;
    }

    @Override
    public String getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getCount() {
        return data.size();
    }
}
